package com.wx.auth.util;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import net.sf.json.JSONObject;

public class AuthUtil {
	public static final String APPID="wx6d6d0eabe8392e5a";
	public static final String APPSECRET="6be3dff05e5da4584abdc9e90146b36b";
	
	public static JSONObject doGetJson(String url) throws ClientProtocolException, IOException {
		
		JSONObject jsonObject=null;
		DefaultHttpClient client=new DefaultHttpClient();//初始化httpclient对象 
		HttpGet httpGet=new HttpGet(url);//通过get方式进行提交
		HttpResponse response=client.execute(httpGet);//使用execute()方法发送请求，此处会抛出异常
		HttpEntity entity=response.getEntity();//从response中获取结果
		if (entity!=null) {
			String result=EntityUtils.toString(entity,"utf-8");
			jsonObject=JSONObject.fromObject(result);//将String对象装换成json
		}
		 httpGet.releaseConnection();//把连接释放掉
		return jsonObject;
	}
}
